layer = undefined;//全局变量layui弹出层，后面的js会赋值
SV = function (service) {
    return function (method) {
        return function () {
            var rtv;
            var _ = alert;
            if (layer) {
                _ = function (msg) {
                    layer.alert(msg, {
                        skin: 'adp-error-layer-class',
                        title: '出错啦!',
                        closeBtn: 0,
                        anim: 4 //动画类型
                    });
                }
            }

            $.post({
                url: "/" + AdpWebContext + "/rs/" + service + "/" + method,
                contentType: "application/json; charset=utf-8",
                async: false,
                cache: false,
                data: JSON.stringify(arguments.length > 0 ? arguments[0] : {})


            }).error(function (data) {
                if (data.status == 401) {
                    // parent.window.location.href = "/" + AdpWebContext + "/login.html";
                } else {
                    _(data.status + ":" + data.responseText);
                }

            }).success(function (data) {
                rtv = data;
            });
            if (rtv && rtv.error) {
                _(rtv.error);
            }
            return rtv;
        }

    }
};


Download = function (service) {
    return function (method) {
        return function () {

            var url = "/" + AdpWebContext + "/rs/" + service + "/" + method + "/download";
            var data = JSON.stringify(arguments.length > 0 ? arguments[0] : {});
            var form = $("<form>").attr({"style": "display:none", "method": "post", "action": url});
            var input = $("<input>").attr({"type": "hidden", "name": "data", "value": data});
            $("body").append(form);
            form.append(input).submit().remove();
        }

    }
};

function showNotice(title, msg) {
    var Notification = window.Notification || window.mozNotification || window.webkitNotification;
    if (Notification) {
        Notification.requestPermission(function (status) {
            //status默认值'default'等同于拒绝 'denied' 意味着用户不想要通知 'granted' 意味着用户同意启用通知
            if ("granted" != status) {
                return;
            } else {
                var tag = "sds" + Math.random();
                var notify = new Notification(
                    title,
                    {
                        dir: 'auto',
                        lang: 'zh-CN',
                        tag: tag,//实例化的notification的id
                        icon: '/favicon.ico',//通知的缩略图,//icon 支持ico、png、jpg、jpeg格式
                        body: msg //通知的具体内容
                    }
                );
                notify.onclick = function () {
                    //如果通知消息被点击,通知窗口将被激活
                    console.log("如果通知消息被点击,通知窗口将被激活！！！");
                    window.focus();
                };
                notify.onerror = function () {
                    console.log("HTML5桌面消息出错！！！");
                };
                notify.onshow = function () {
                    setTimeout(function () {
                        notify.close();
                    }, 20000)
                };
                notify.onclose = function () {
                    console.log("HTML5桌面消息关闭！！！");
                };
            }
        });
    } else {
        console.log("您的浏览器不支持桌面消息");
    }
}

if (window.indexedDB) {
    console.log("您的浏览器支持IndexedDB数据库。");
} else {
    alert("您的浏览器不支持IndexedDB数据库。");
}
var DBOpenRequest = window.indexedDB.open('project', 1);
// 数据库打开成功后
DBOpenRequest.onsuccess = function (event) {
    // 存储数据结果
    db = DBOpenRequest.result;
    // 做其他事情...
};

// 下面事情执行于：数据库首次创建版本，或者window.indexedDB.open传递的新版本（版本数值要比现在的高）
DBOpenRequest.onupgradeneeded = function (event) {
    var db = DBOpenRequest.result;//获得数据库实例对象
    if (!db.objectStoreNames.contains("adpTable")) {                   //判断对象存储空间名称是否已经存在
        var objectStore = db.createObjectStore("adpTable", {keyPath: "id"});//创建adpTable对象存储空间;指定keyPath选项为id（即主键为id）
        //对象存储空间adpTable的列email上创建一个唯一索引email,可以创建多个索引。
        objectStore.createIndex("email",                                //索引名
            "email",                                //创建索引的列（即keyPath,索引属性字段名）
            {unique: true});                      //索引选项(索引属性值是否唯一:true or false)
    }
};


session = SV("Login")("getLoginUser")();


NAVIGATION = NAVIGATION.map(function (m) {
    var menulist = m.subNavigation;
    menulist = menulist.filter(function (item) {
        if (item.authTo) {
            if(session.roles){
                for (var i = 0; i < session.roles.length; i++) {
                    if (session.roles[i].roleType == "admin") {
                        return true;
                    }
                }

                for (var j = 0; j < session.permissions.length; j++) {
                    var permission = session.permissions[j];
                    var arr = item.authTo.split(",");
                    for (var k = 0; k < arr.length; k++) {
                        if (arr[k] == permission) {
                            return true;
                        }
                    }
                }
            }


            return false;
        }
        return true;
    });
    m.subNavigation = menulist;
    return m;
}).filter(function (mm) {
    return mm.subNavigation.length > 0;
});

$('#larry-nav-side').find("ul").append(template("navitpl", {list: NAVIGATION}));
$('.layui-larry-menu').append(template("shortcutMenuTpl", {list: SHORTCUTMENU}));


var HTML_TEMPLATE = {
    FORM_TEXT_TPL: FORM_TEXT_TPL.innerHTML,
    FORM_DEPT_TPL: FORM_DEPT_TPL.innerHTML,
    FORM_SELECT_TPL: FORM_SELECT_TPL.innerHTML,
    FORM_BUTTONS_TPL: FORM_BUTTONS_TPL.innerHTML,
    FORM_SWITCH_TPL: FORM_SWITCH_TPL.innerHTML,
    FORM_RADIO_TPL: FORM_RADIO_TPL.innerHTML,
    FORM_TEXTAREA_TPL: FORM_TEXTAREA_TPL.innerHTML,
    FORM_HIDDEN_TPL: FORM_HIDDEN_TPL.innerHTML,
    FORM_DATE_TPL: FORM_DATE_TPL.innerHTML,
    FORM_CUSTOM_TPL: FORM_CUSTOM_TPL.innerHTML,
    FORM_CHECKBOX_TPL: FORM_CHECKBOX_TPL.innerHTML,
    FORM_UPLOADER_TPL: FORM_UPLOADER_TPL.innerHTML
};



